package org.zzz.mapper;

import org.apache.ibatis.annotations.*;
import org.zzz.entity.Course;
import org.zzz.entity.vo.CourseShowVo;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:23
 */
public interface CourseMapper {
    /**
     * 获取所有课程
     * @return
     */
    @Select("select * from course")
    List<Course> listCourse();

    /**
     * 根据课程号获取课程信息
     * @param id
     * @return
     */
    @Select("select * from course where id = #{id}")
    Course getCourseById(@Param("id") String id);

    /**
     * 添加课程
     * @param course
     * @return
     */
    @Insert("insert into course value(#{id},#{name})")
    int insertCourse(Course course);

    /**
     * 根据课程id修改课程
     * @param course
     * @return
     */
    @Update("update course set name = #{name} where id = #{id}")
    int updateCourse(Course course);

    /**
     * 根据课程id删除课程
     * @param id
     * @return
     */
    @Delete("delete from course where id = #{id}")
    int deleteCourseById(@Param("id") String id);

    /**
     * 获取所有课程信息展示
     * @return
     */
    @Select("select c.id, c.name " +
            "from course c ")
    List<CourseShowVo> listCourseShowVo();

    @Select("select c.id, c.name " +
            "from course c where c.id = #{cid}")
    CourseShowVo getCourseShowVoByCid(@Param("cid") String cid);

    @Select("select c.id, c.name " +
            "from course c where c.name = #{cname}")
    CourseShowVo getCourseShowVoByCname(@Param("cname") String cname);
}
